package com.sgu6.sgu6_machine.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import android.view.MenuItem;
import android.widget.ExpandableListView;

import com.sgu6.sgu6_machine.R;
import com.sgu6.sgu6_machine.adapter.InstructionAdapter;
import com.sgu6.sgu6_machine.base.BaseA;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 用户使用后台设置说明
 */
public class UserInstructionA extends BaseA {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.elvInstruction)
    ExpandableListView elvInstruction;

    private List<String> group = new ArrayList<>();
    private List<List<String>> child = new ArrayList<>();
    private InstructionAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_instruction);
        ButterKnife.bind(this);

        initUI();

        adapter = new InstructionAdapter(this, group, child);

        elvInstruction.setAdapter(adapter);
    }

    private void initToolbar() {
        toolbar.setTitle("使用说明");
        toolbar.setTitleTextColor(Color.WHITE);
        toolbar.setBackgroundResource(R.color.colorPrimaryDark);
        setSupportActionBar(toolbar);

        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return true;
    }

    @Override
    public void initUI() {
        initToolbar();
        initData();
    }

    /**
     * 初始化数据
     */
    private void initData() {
        group.addAll(Arrays.asList(getResources().getStringArray(R.array.instruction_group)));

        child.add(Arrays.asList(getResources().getStringArray(R.array.instruction_group_test)));
        child.add(Arrays.asList(getResources().getStringArray(R.array.instruction_group_accuracy)));
        child.add(Arrays.asList(getResources().getStringArray(R.array.instruction_group_weight)));
        child.add(Arrays.asList(getResources().getStringArray(R.array.instruction_group_motor)));
        child.add(Arrays.asList(getResources().getStringArray(R.array.instruction_group_warn)));
        child.add(Arrays.asList(getResources().getStringArray(R.array.instruction_group_temp)));
        child.add(Arrays.asList(getResources().getStringArray(R.array.instruction_group_barn)));
        child.add(Arrays.asList(getResources().getStringArray(R.array.instruction_group_door)));
    }
}
